package com.hz.zbl.mapper;

import com.hz.zbl.entity.BlogEntity;
import com.hz.zbl.entity.CommentsEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BlogMapper {

    @Insert("INSERT INTO blogs VALUES (null, #{title}, #{content}, #{author_id}, #{author_username}, #{author_realname}, #{publish_time}, #{is_anonymous}, #{anonymous_name})")
    int addBlog(BlogEntity blogEntity);

    @Delete("DELETE FROM blogs WHERE id = #{id}")
    int deleteBlog(@Param("id") int id);

    @Select("SELECT * FROM blogs ")
    List<BlogEntity> allBlogs();

    @Select("SELECT * FROM blogs WHERE id = #{id}")
    BlogEntity selectBlogById(@Param("id") int id);

    @Update("UPDATE blogs SET title = #{title}, content = #{content} WHERE id = #{id}")
    int updateBlog(@Param("id") int id, @Param("title") String title, @Param("content") String content);

    @Select("SELECT * FROM blogs WHERE author_id = #{author_id}")
    List<BlogEntity> myBlogs(@Param("author_id") int author_id);



    //添加评论
    @Insert("INSERT INTO comments VALUES (null, #{blog_id}, #{username}, #{content}, #{publish_time}, #{is_anonymous})")
    int addComment(CommentsEntity commentsEntity);

    @Select("SELECT * FROM comments WHERE blog_id = #{blog_id}")
    List<CommentsEntity> certainBlogComments(@Param("blog_id") int blog_id);
}
